﻿using System;
using System.Collections.Generic;
using System.Text;

namespace ESoft.Core.Web.VO
{
    public class ResponseResult
    {
        public const int LOGIN_TIME_OUT = 200;
        public const int APPLICATION_ERROR = 201;
        public const int SYSTEM_ERROR = 203;

        public int Code { get; set; } = 0;
        public ResponseResult(bool v)
        {
            this.IsSuccessed = v;
        }

        public ResponseResult(bool IsSuccessed, Object Result)
        {
            this.IsSuccessed = IsSuccessed;
            this.Result = Result;
        }

        public ResponseResult(bool isSuccessed, Object result, Object errorMessage)
        {
            this.IsSuccessed = isSuccessed;
            this.Result = result;
            this.ErrorMessage = errorMessage;
        }

        public static ResponseResult CreateResult(bool isSuccessed, Object result, Object errorMessage)
        {
            return new ResponseResult(isSuccessed, result, errorMessage);
        }

        public static ResponseResult Success(Object result)
        {
            return new ResponseResult(true, result);
        }
        public static ResponseResult FailOut(Exception result)
        {
            var res = new ResponseResult(false, result.Message, result);
            res.Code = APPLICATION_ERROR;
            return res;
        }
        public static ResponseResult FailOut(int code, Exception result)
        {
            var res = new ResponseResult(false, result.Message, result);
            res.Code = code;
            return res;
        }
        public static object FailOut(string v)
        {
            return FailOut(new Exception(v));
        }
        public static ResponseResult Success()
        {
            return new ResponseResult(true);
        }
        public bool IsSuccessed { get; set; }
        public Object Result { get; set; }

        public Object ErrorMessage { get; set; }


    }
}
